package cn.snmp.mutual.nms;

public class SnmpInt extends SnmpVar
{
    int value;
    byte[] byteValue;
    
    public SnmpInt(final int i) {
        this.value = 0;
        this.value = i;
        this.Type = 2;
    }
    
    @Override
    int encode(final byte[] abyte0, final int i) throws ArrayIndexOutOfBoundsException {
        return ASNTypes.encodeInt(abyte0, i, this.value, 2);
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (obj != null && obj instanceof SnmpInt) {
            final SnmpInt snmpint = (SnmpInt)obj;
            return this.value == snmpint.intValue();
        }
        return false;
    }
    
    @Override
    public Object getVarObject() {
        return this.toValue();
    }
    
    public int intValue() {
        return this.value;
    }
    
    @Override
    public byte[] toBytes() {
        if (this.byteValue == null) {
            this.byteValue = new byte[4];
            int i = this.value;
            int j = this.byteValue.length;
            while (i != 0) {
                this.byteValue[--j] = (byte)(i & 0xFF);
                i >>>= 8;
            }
        }
        return this.byteValue;
    }
    
    @Override
    public String toString() {
        return Integer.toString(this.value);
    }
    
    @Override
    public String toTagString() {
        return "INTEGER : " + Integer.toString(this.value);
    }
    
    @Override
    public Object toValue() {
        return new Integer(this.value);
    }
}
